function SearchCtrl($rootScope, $scope, $timeout, $http, $routeParams,
		autocompleteService) {

	$scope.searchRq = {};
	$scope.results = [];
	$scope.pages = [];
	$scope.currentPage = 0;

	$scope.$on('$viewContentLoaded', function(event) {
		alert("Finish");
	});

	$scope.initSearch = function() {
		$http.post(DOMAIN + '/data/search/get').success(function(data) {
			$scope.searchRq = data;
			$scope.searchRq.manufacturer = [];
			if($.trim($scope.searchRq.content) != "") {
				$scope.search();
			}
		});
	};

	$scope.search = function() {
		$http.post(DOMAIN + '/data/search/search', $scope.searchRq).success(
				function(data) {
					$scope.results = data;
					var pages = Math.ceil(data.length / $scope.pageSize) - 1;
					$scope.pages = [];
					for(var i = 1; i<= pages; i++) {
						$scope.pages.push(i);
					}
					// $timeout(function() {
					// $.scrollTo('#scrollTo', 1000);
					// }, 1000);

				});
	};

	$scope.advSearch = function() {
		$('.advSearchBox').slideToggle();
	};

	$scope.addManufacturer = function(item) {
		$scope.searchRq.manufacturer.push(item.id);
		$http.get();
	};

	$scope.getManufactorers = function() {
		$http.get(DOMAIN + '/data/manufacturer/getall').success(
				function(data) {
					$scope.manufacturerList = data;
					autocompleteService.init($("#textManufacturer"),
							$scope.manufacturerList, $scope.addManufacturer);
				});
	};

	$scope.addSearchText = function(item) {
		$scope.searchRq.content = item.name;
		$http.get();
	};

	$scope.getClasses = function() {
		$http.get(DOMAIN + '/data/search/getclass').success(
				function(data) {
					$scope.classList = data;
					autocompleteService.init($("#searchContent"),
							$scope.classList, $scope.addSearchText);
				});
	};
	
	$scope.changePage = function(page) { 
		$scope.currentPage = page;
	};

	// --------- INIT ----------------
	$scope.initSearch();
	$scope.getManufactorers();
	$scope.getClasses();

}
SiteCtrl.$inject = [ '$rootScope', '$scope', '$timeout', '$http', '$routeParams',
		'autocompleteService' ];